/**
 * 框架核心类 - 应用入口
 */
export class Stone {
    constructor() {
      this.components = [];
      this.theme = {
        mode: 'light',
        primaryColor: '#4285f4',
        textColor: '#333',
        backgroundColor: '#fff'
      };
    }
  
    addComponent(component) {
      this.components.push(component);
      component.theme = this.theme; // 注入主题
    }
  
    toggleTheme() {
      // 切换主题
      this.theme = this.theme.mode === 'dark' ? 
        { mode: 'light', primaryColor: '#4285f4', textColor: '#333', backgroundColor: '#fff' } : 
        { mode: 'dark', primaryColor: '#34a853', textColor: '#fff', backgroundColor: '#222' };
      
      // 更新页面背景
      document.body.style.backgroundColor = this.theme.backgroundColor;
      document.body.style.color = this.theme.textColor;
      
      // 更新所有组件的主题
      this.components.forEach(comp => {
        comp.theme = this.theme;
        if (comp.applyStyle) {
          comp.applyStyle(); // 重新应用样式
        }
        if (comp.update) {
          comp.update(); // 更新组件
        }
      });
      
      console.log('主题已切换到:', this.theme.mode);
    }
  
    render() {
      // 初始化页面样式
      document.body.style.backgroundColor = this.theme.backgroundColor;
      document.body.style.color = this.theme.textColor;
      document.body.style.transition = 'background-color 0.3s, color 0.3s';
      
      this.components.forEach(component => {
        if (component.render) {
          component.render();
        }
      });
    }
  }